
public class ticketsWindow implements java.lang.Runnable {

    private int tickets =100;

    @Override
    public void run() {
        while (true){
            if (tickets>0){
                System.out.println(Thread.currentThread().getName()+"正在卖"+--tickets+"票！");
                try{
                    Thread.sleep(500);
                } catch (Exception e){
                    e.printStackTrace();
                }
            }
            if (tickets == 0){
                System.exit(1);
            }
        }

    }
}

class test{
    public static void main(String[] args) {
      ticketsWindow t = new ticketsWindow();
      new Thread(t,"窗口1").start();
      new Thread(t,"窗口2").start();
      new Thread(t,"窗口3").start();

    }
}